#include <hash.h>
#include "devices/block.h"
#include "filesys/off_t.h"
#include "threads/synch.h"

/* Virtual page. */
struct page 
  {
    void *addr;                 /* User virtual address. */
    bool read_only;             /* Read-only page? */
    struct thread *thread;      /* Owning thread. */

    struct hash_elem hash_elem; /* struct thread `pages' hash element. */

    struct frame *frame;        /* Page frame. */

    bool needToWriteBack;

    block_sector_t sector;       /* Starting sector of swap area, or -1. */
    
    struct file *file;          /* File. */
    off_t file_offset;          /* Offset in file. */
    off_t file_bytes;           /* Bytes to read/write, 1...PGSIZE. */
  };


struct page *page_allocate (void *, bool read_only);
void page_deallocate (void *vaddr);
bool page_in (void *fault_addr);
void page_exit (void);
struct page* find_page(void *vaddr);
bool page_accessed_recently (struct page *p);
bool page_out (struct page *p);
hash_hash_func page_hash;
hash_less_func page_less;